import { NIcon } from "naive-ui";
import { h } from "vue";
import CryptoJS from 'crypto-js';

/**
 * render 图标
 * */
export function renderIcon(icon) {
  return () => h(NIcon, null, { default: () => h(icon) });
}
/**
 * render 图标
 * */
export function renderIconSize(icon, size) {
  return () => h(NIcon, { size: size }, { default: () => h(icon) });
}
/**
 * font 图标(Font class)
 * */
export function renderFontClassIcon(icon: string, iconName = "iconfont") {
  return () => h("span", { class: [iconName, icon] });
}
/**
 * font 图标(Unicode)
 * */
export function renderUnicodeIcon(icon: string, iconName = "iconfont") {
  return () => h("span", { class: [iconName], innerHTML: icon });
}
/**
 * font svg 图标
 * */
export function renderfontsvg(icon) {
  return () =>
    h(NIcon, null, {
      default: () =>
        h(
          "svg",
          { class: `icon`, "aria-hidden": "true" },
          h("use", { "xlink:href": `#${icon}` })
        ),
    });
}
/**
 * 当前时间的秒级时间戳
 * @return {number} 秒级单位
 */
export function currentTime(): number {
  return Math.round(new Date().getTime()/1000)
}
/**
 * 生成 youdao 翻译需要的sign
 * @param {string} data 应用ID+input+salt+curtime+应用密钥
 */
export function youdaoSign(data: string): string {
  return CryptoJS.SHA256(data).toString(CryptoJS.enc.Hex)
}